package multidraw.tools;

import java.awt.Point;
import java.awt.event.MouseEvent;

import multidraw.model.DrawingCanvasModel;
import multidraw.model.FreehandShape;
import multidraw.model.Shape;



public class FreehandShapeTool extends Tool {	
	protected FreehandShapeFactory factory;
	protected FreehandShape shape;
	//protected Point startingMousePosition;
	//protected Point currentMousePosition;
	
	public FreehandShapeTool(DrawingCanvasModel myModel, FreehandShapeFactory factory) {
		this.myModel = myModel;
		this.factory = factory;		
	}

	
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		shape = factory.createShape(e.getPoint(), myModel.getPenColor(), 
				myModel.getNextID());
		myModel.notifyObservers();
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		//add shape to the model and return to the normal state
		myModel.addShape((Shape)shape);
		shape = null;
		//notify observers
		myModel.notifyObservers();
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		if (shape != null) {
			shape.addPoint(e.getPoint());
		}
		
		//update model's views
		myModel.notifyObservers();
	}

	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Shape getShape() {
		// TODO Auto-generated method stub
		return shape;
	}

}
